package com.atguigu.mq.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author KEIO  on 2021/8/31.
 * @version 1.0
 */
@Api(tags = "发送消息")
@RestController
@Slf4j
@RequestMapping("/mq")
public class SendMessage {


    @Autowired
    RabbitTemplate rabbitTemplate;

    @Value("${PunchClock.name}")
    private String name;


    @ApiOperation("简单发送消息")
    @GetMapping("/send/{message}")
    public void sendMessage( @ApiParam(name = "message" , example = "路径参数必须始终命名为它们所代表的路径部分")@PathVariable String message){
        log.info("当前消息发送时间{} ,  消息内容{}" , new DateTime(new Date()).toString("yyyy-MM-dd HH:mm:ss"), message);

        SimpleDateFormat format = new SimpleDateFormat("dd");
        SimpleDateFormat format1 = new SimpleDateFormat("HH");
        String day = format.format(new Date());
        String hour = format1.format(new Date());
        Long times = System.currentTimeMillis();
        String timestamp = times.toString().substring(0, 10);
        log.info("当前消息发送日{} ,  小时{} , 时间戳{}" , day, hour, timestamp);

        rabbitTemplate.convertAndSend("X", "XA", "消息来自ttl为10s的队列" + message);
        rabbitTemplate.convertAndSend("X", "XB", "消息来自ttl为40s的队列" + message);


    }




}
